/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Merlion.MRP.entity;

import Merlion.SCM.entity.ProductEntity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

@Entity
public class UnplannedMaterialRequirementEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date requestedOn;
    private String remarks;
    private String status;
    @OneToOne
    private UnplannedDailyDemandEntity unplannedDailyDemand;
    private double bomMultiplier;
    @ManyToOne
    private WeeklyMaterialRequirementEntity weeklyMaterialRequirement;
    private boolean withdrawn;
    private boolean purchased;

    public UnplannedMaterialRequirementEntity() {
    }

    public UnplannedMaterialRequirementEntity(UnplannedDailyDemandEntity unplannedDailyDemand, WeeklyMaterialRequirementEntity weeklyMaterialRequirement) {
        this.unplannedDailyDemand = unplannedDailyDemand;
        this.weeklyMaterialRequirement = weeklyMaterialRequirement;
        ProductEntity product = unplannedDailyDemand.getPlannedDailyDemandEntity().getProduct();
        this.bomMultiplier = unplannedDailyDemand.getQuantity() * product.getCaseWeight() / product.getBOMEntity().getBatchSize();
        this.purchased = false;
        this.withdrawn = false;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public double getBomMultiplier() {
        return bomMultiplier;
    }

    public void setBomMultiplier(double bomMultiplier) {
        this.bomMultiplier = bomMultiplier;
    }

    public WeeklyMaterialRequirementEntity getWeeklyMaterialRequirement() {
        return weeklyMaterialRequirement;
    }

    public void setWeeklyMaterialRequirement(WeeklyMaterialRequirementEntity weeklyMaterialRequirement) {
        this.weeklyMaterialRequirement = weeklyMaterialRequirement;
    }


    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public boolean isPurchased() {
        return purchased;
    }

    public void setPurchased(boolean purchased) {
        this.purchased = purchased;
    }

    
    public boolean isWithdrawn() {
        return withdrawn;
    }

    public void setWithdrawn(boolean withdrawn) {
        this.withdrawn = withdrawn;
    }

    public Date getRequestedOn() {
        return requestedOn;
    }

    public void setRequestedOn(Date requestedOn) {
        this.requestedOn = requestedOn;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public UnplannedDailyDemandEntity getUnplannedDailyDemand() {
        return unplannedDailyDemand;
    }

    public void setUnplannedDailyDemand(UnplannedDailyDemandEntity unplannedDailyDemand) {
        this.unplannedDailyDemand = unplannedDailyDemand;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UnplannedMaterialRequirementEntity)) {
            return false;
        }
        UnplannedMaterialRequirementEntity other = (UnplannedMaterialRequirementEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "Merlion.MRP.entity.UnplannedMaterialRequirementEntity[ id=" + id + " ]";
    }
}
